/**
 * 获取用户指定cookie的值
 * @param { String } key cookiie的键名
 * @returns 返回指定cookie的值，cookie不存在返回空字符
 */
function getCookie(key) {
   const cookies = document.cookie.split(';')
   for (let item of cookies) {
      if (item.includes(key)) {
         return decodeURI(item.split('=')[1])
      }
   }
   return ''
}
/**
 * 设置一条用户登录的cookie
 * @param {STRING} key cookie名
 * @param {STRING} val cookie值
 */
function setCookie(key, val) {
   const exp = new Date();
   exp.setTime(exp.getTime() + 12 * 60 * 60 * 1000);
   document.cookie = key + "=" + escape(val) + ";expires=" + exp.toGMTString() + ";path=/";
}

/**
 * 获取格式化过后时间
 * @param {String} T 中国标准时间
 * @returns 返回格式化过后的时间
 */
function formatDate(T) {
   const time = new Date(T)
   const Y = time.getFullYear()
   const M = time.getMonth() + 1
   const D = time.getDate()
   const HH = time.getHours()
   const MM = time.getMinutes()
   const SS = time.getSeconds()
   return Y + '-' + M + '-' + D + ' ' + HH + ':' + MM + ':' + SS
}

export {
   getCookie,
   setCookie,
   formatDate
}